package com.blog.blog.dto;

/**
 * 文章列表查询 DTO
 */
public class ArticleListQueryDTO {
    private String keyword;

    private Long categoryId;

    private Integer status; // 0-草稿，1-发布，2-置顶

    private Long tagId;

    /**
     * 作者ID（用于数据权限：当角色 data_scope=SELF 时按作者过滤）
     */
    private Long authorId;

    private Integer pageNo = 1;

    private Integer pageSize = 10;

    /**
     * 排序字段：latest(默认)、views、likes、comments
     */
    private String sortBy;

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public Long getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTagId() {
        return tagId;
    }

    public void setTagId(Long tagId) {
        this.tagId = tagId;
    }

    public Long getAuthorId() {
        return authorId;
    }

    public void setAuthorId(Long authorId) {
        this.authorId = authorId;
    }

    /**
     * SQL分页偏移量
     */
    public Integer getOffset() {
        int p = (pageNo == null || pageNo < 1) ? 1 : pageNo;
        int s = (pageSize == null || pageSize < 1) ? 10 : Math.min(pageSize, 100);
        return (p - 1) * s;
    }

    public String getSortBy() {
        return sortBy;
    }

    public void setSortBy(String sortBy) {
        this.sortBy = sortBy;
    }
}


